package com.event.gateway;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.io.File;

@SpringBootApplication
@Slf4j
public class GatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
        log.info("✅ 网关服务启动成功！");
        log.info("🌐 网关服务地址：{}", "http://localhost:8089");
    }
    
    @Bean
    public CommandLineRunner logEnvironmentInfo() {
        return args -> {
            log.info("=== 环境信息 ===");
            log.info("当前工作目录: {}", System.getProperty("user.dir"));
            log.info("根目录eventsys属性: {}", System.getProperty("image.root-dir"));
            log.info("上传目录访问路径: {}", "http://localhost:8089/images/");
            
            // 输出系统属性
            log.info("操作系统: {}", System.getProperty("os.name"));
            log.info("Java版本: {}", System.getProperty("java.version"));
            
            // 检查常用目录
            String workDir = System.getProperty("user.dir");
            File uploadsDir = new File(workDir, "../uploads/images");
            log.info("相对上传目录存在: {} (路径: {})", 
                    uploadsDir.exists(), uploadsDir.getAbsolutePath());
            
            // 查找eventsys目录
            File currentDir = new File(workDir);
            while (currentDir != null && !currentDir.getName().equals("eventsys")) {
                currentDir = currentDir.getParentFile();
            }
            
            if (currentDir != null) {
                log.info("找到eventsys目录: {}", currentDir.getAbsolutePath());
                File imagesDir = new File(currentDir, "uploads/images");
                log.info("eventsys下的images目录: {} (路径: {})", 
                        imagesDir.exists(), imagesDir.getAbsolutePath());
            } else {
                log.warn("未找到eventsys目录");
            }
            
            log.info("=== 环境检查完成 ===");
        };
    }
} 